Skip to content

fix(display): keep enumeration alive without source id 0 - #1238

Merged
Yundi339 merged 1 commit into
masterfrom
fix/display-enum-missing-source
Nov 12, 2026
Merged

Yundi339 merged 1 commit into
masterfrom
fix/display-enum-missing-source

Conversation

@Yundi339

Copy link
Copy Markdown
Member

改了啥呀

  • 枚举显示器时,不再假定没有活动源的设备一定有 source id 0。
  • 优先使用已经记录的活动源;没有活动源,或者活动源不在路径表里时,改用该设备现有路径里索引最小的一条。
  • 路径缺失或索引越界时跳过这台设备并记警告,不再让 std::out_of_range 直接终止进程。
  • 同一设备后面才出现的活动路径,也会补记为活动源。Windows 通常把活动路径排在前面,这里只是这条假设不成立时的兜底。

为啥要改

启动恢复显示状态时会枚举全部显示路径。残缺或虚拟适配器经常没有活动源,源 ID 也不是 0。旧代码用 map::at(0),抛出的 std::out_of_range 没有被接住,进程以 0xC0000409 退出。取显示名失败本身只是日志,真正让进程起不来的是这次查表。

上游在 LizardByte/libdisplaydevice#146 修过同一处,Sunshine #3770 确认 v2025.409.140403 之后不再崩溃。Foundation 仍保留着修之前的写法。上游后来的 undock 布局恢复没有再改这个查表,不在这次范围内。

同一条显示路径上,持久化 JSON 解析和源模式索引已经有异常或越界处理,不会以同样的方式在启动时终止进程。

验证

  • git diff --check
  • 没有在带有这类残缺适配器的机器上重新启动验证。正常有活动源的显示器仍走原来的活动源路径。

Devices with no active source do not necessarily expose source id 0. Looking that id up during startup threw std::out_of_range and aborted the process.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • 问题修复
    • 改善了 Windows 显示设备的识别稳定性,不再受显示路径排列顺序影响。
    • 无法找到有效显示路径的设备将被跳过;没有可识别设备时会正确返回无可用设备的状态。

Walkthrough

Windows 设备拓扑代码现在记录活动路径的 source ID,并使用代表路径选择结果枚举设备。路径不可用或无有效设备时,代码会记录警告并跳过设备或返回 boost::none。

Changes

Windows 显示设备路径选择

Layer / File(s) Summary
记录并选择代表路径
src/platform/windows/display_device/device_topology.cpp
make_device_path_data 记录首次遇到的活动路径 source ID。representative_path_index 优先选择该 source ID 对应的路径;若路径缺失,则回退到索引最小的可用路径。枚举过程跳过无有效索引的设备;若 CCD 返回路径但没有枚举到有效设备,则返回 boost::none。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: qiin2333

Merge Risk: Minimal · up to beab0

The change keeps display enumeration from crashing when a device has no source id 0 or no active source. No actionable merge-blocking risk remains. The author did not retest on a machine with an incomplete adapter.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“fix(display): keep enumeration alive without source id 0”与变更内容相符。变更移除了对无活动源设备必为源 ID 0 的假设,改用已记录的活动源或索引最小的路径,并在越界时跳过设备,从而避免 map::at(0) 抛出 std::out_of_range 导致进程终止。标题指出了主要修复点,并具体说明了显示枚举相关的问题。
Description check Passed 描述与变更直接相关。描述说明了枚举显示器时不再假定源 ID 为 0、活动源的回退策略、越界时跳过设备并记录警告、同一设备后出现的活动路径也会被记录,并给出了崩溃背景和验证方式。这些内容都对应 device_topology.cpp 中的改动。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6225dcb and beab033.

Files selected for processing: 1

  • src/platform/windows/display_device/device_topology.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: VDD helper smoke tests
  • GitHub Check: Setup Release
  • GitHub Check: MAT software regressions
Additional context used

Path-based instructions: 2

平台抽象层代码(Windows/Linux/macOS)。确保各平台实现一致, 注意 Windows API 调用的错误处理和资源释放。

CodeRabbit configuration file

Files:

  • src/platform/windows/display_device/device_topology.cpp
Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。

CodeRabbit configuration file

Files:

  • src/platform/windows/display_device/device_topology.cpp

@Yundi339
Yundi339 merged commit 4ead343 into master Nov 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant